package del5;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

public class WriterFork extends Writer{
	Writer a;
	Writer b;
	
	public WriterFork(Writer a, Writer b){
		this.a = a;
		this.b = b;
	}

	@Override
	public void close() throws IOException {
		a.close();
		b.close();		
	}

	@Override
	public void flush() throws IOException {
		a.flush();
		b.flush();
	}

	@Override
	public void write(char[] arg0, int arg1, int arg2) throws IOException {
		a.write(arg0, arg1, arg2);
		b.write(arg0, arg1, arg2);
	}
	
	@Override
	public void write(char[] cbuf) throws IOException {
		a.write(cbuf);
		b.write(cbuf);
	}
	
	@Override
	public void write(int c) throws IOException {
		a.write(c);
		b.write(c);
	}
	
	@Override
	public void write(String s) throws IOException {
		a.write(s);
		b.write(s);
	}
	
	@Override
	public void write(String s, int off, int len) throws IOException {
		a.write(s, off, len);
		b.write(s, off, len);
	}
	
	public static void main(String[] args) throws IOException{
		FileWriter fw = new FileWriter("testfile.txt");
		PrintWriter pw = new PrintWriter(System.out);
		
		WriterFork wf = new WriterFork(fw, pw);
		
		wf.write("This is one awesome test!\n");
		wf.write("The purpose of life is 42!\n");
		wf.write("Muhahaha.. Bye!");
		
		wf.flush();
		wf.close();
	}
}
